<ListBox x:Class="TagFlo.SetListBox"
		 
		 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Loaded="OnInit" 

    AllowDrop="True" >


    <ListBox.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Resources\ResourceDictionary.xaml"/>
                <ResourceDictionary Source="..\Resources\ControlStyle.xaml"/>
                <ResourceDictionary Source="..\Themes\current.theme.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="ComboBoxItemTemplate">

                <TextBlock Text="{Binding Path=PhotoSetName}"/>
            </DataTemplate>

            <DataTemplate x:Key="ScrollViewerItemTemplate">


                <Grid Width="75" Height="75"
				VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,0,5,0">

                    <Border  Padding="4"   BorderBrush="{StaticResource BorderBrush}" Background="White" BorderThickness="1" CornerRadius="4" >


                        <Image Source="{Binding Path=Thumbnail}" Width="65" Height="65"/>




                        <Border.ToolTip>
                            <TextBlock x:Name="PhotoItemText" >
							<TextBlock.Text>
								<Binding Mode="OneWay" Path="Title" />
							</TextBlock.Text>
                            </TextBlock>
                        </Border.ToolTip>

                    </Border>


                </Grid>


            </DataTemplate>


            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="OverridesDefaultStyle" Value="True" />

                <Setter Property="Template">

                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                            <Grid>
                                <!--<Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>-->
                                <Border Grid.Row="0">
                                    <ScrollContentPresenter CanContentScroll="True" Content="{TemplateBinding ScrollViewer.Content}" />
                                </Border>
                                <!--<ScrollBar Orientation="Vertical" Grid.Row="0" Grid.Column="0" Minimum="0" Maximum="{TemplateBinding ScrollViewer.ScrollableHeight}" Value="{TemplateBinding ScrollViewer.VerticalOffset}" ViewportSize="{TemplateBinding ScrollViewer.ViewportHeight}" Name="PART_VerticalScrollBar" Visibility="{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}" />-->
                                <ScrollBar Orientation="Horizontal" Minimum="0" Maximum="{TemplateBinding ScrollViewer.ScrollableWidth}"
                                           Value="{TemplateBinding ScrollViewer.HorizontalOffset}"
                                           ViewportSize="{TemplateBinding ScrollViewer.ViewportWidth}"
                                           Name="PART_HorizontalScrollBar"
                                         Visibility="{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}"  
                                           VerticalAlignment="Center"/>

                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ScrollBar_LineButton" TargetType="{x:Type RepeatButton}">
                <Setter Property="OverridesDefaultStyle" Value="true" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                            <Border x:Name="Border" CornerRadius="1" Opacity=".5" BorderBrush="{StaticResource BorderBrush}" BorderThickness="2" Background="{StaticResource PanelBackgroundBrush}">
                                <!--<Border.Background>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset="0" Color="White"/>
                                            <GradientStop Offset="1" Color="#CDCDCD"/>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Border.Background>-->
                                <Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{StaticResource ForegroundBrush}" Data="{Binding Path=Content,
                       RelativeSource={RelativeSource TemplatedParent}}"  />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter TargetName="Border" Property="Opacity" Value="1"/>
                                    <!--<Setter TargetName="Border" Property="Background" Value="{StaticResource BackgroundBrush}">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                                <LinearGradientBrush.GradientStops>
                                                    <GradientStop Offset="0" Color="White"/>
                                                    <GradientStop Offset="1" Color="#E0E0E0"/>
                                                </LinearGradientBrush.GradientStops>
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>-->
                                    <!--<Setter TargetName="Border" Property="BorderBrush" Value="Gray" />-->
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter TargetName="Border" Property="Visibility" Value="Hidden"/>

                                </Trigger>
                                <Trigger Property="IsPressed" Value="true">
                                    <Setter TargetName="Border" Property="Background">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                                <LinearGradientBrush.GradientStops>
                                                    <GradientStop Offset="0" Color="#EEEEEE"/>
                                                    <GradientStop Offset="1" Color="#DFDFDF"/>
                                                </LinearGradientBrush.GradientStops>
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ScrollBar_PageButton" TargetType="{x:Type RepeatButton}">
                <Setter Property="OverridesDefaultStyle" Value="true" />
                <Setter Property="IsTabStop" Value="false" />
                <Setter Property="Focusable" Value="false" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                            <Rectangle Fill="Transparent" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!--<Style x:Key="ScrollBar_Thumb" TargetType="{x:Type Thumb}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Thumb}">
                            <Border CornerRadius="3" BorderBrush="Silver" BorderThickness="1">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset="0" Color="LightSteelBlue"/>
                                            <GradientStop Offset="1" Color="White"/>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>-->
            <!-- ScrollBar Style -->

            <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
                <Setter Property="Stylus.IsFlicksEnabled" Value="false" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="Width" Value="16" />
                <Setter Property="MinWidth" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ScrollBar}">
                            <Grid >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="16" />
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="16" />
                                </Grid.RowDefinitions>
                                <RepeatButton Grid.Row="0" Style="{DynamicResource ScrollBar_LineButton}" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 7 4 L 3.5 0 Z" />
                                <!--<Border Grid.Row="1" BorderBrush="DarkBlue" BorderThickness="1" Background="{TemplateBinding Background}" CornerRadius="2" />
                                <Track Grid.Row="1" Name="PART_Track" IsDirectionReversed="true">
                                    <Track.DecreaseRepeatButton>
                                        <RepeatButton Style="{StaticResource ScrollBar_PageButton}"/>
                                    </Track.DecreaseRepeatButton>
                                    <Track.Thumb>
                                        <Thumb Style="{StaticResource ScrollBar_Thumb}" MinHeight="4"/>
                                    </Track.Thumb>
                                    <Track.IncreaseRepeatButton>
                                        <RepeatButton Style="{StaticResource ScrollBar_PageButton}"/>
                                    </Track.IncreaseRepeatButton>
                                </Track>-->
                                <RepeatButton Grid.Row="2" Style="{DynamicResource ScrollBar_LineButton}" Command="ScrollBar.LineDownCommand" Content="M 0 0 L 3.5 4 L 7 0 Z" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="Orientation" Value="Horizontal">
                        <Setter Property="Width" Value="Auto" />
                        <Setter Property="MinWidth" Value="0" />
                        <Setter Property="Height" Value="16" />
                        <Setter Property="MinHeight" Value="16" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ScrollBar}">
                                    <Grid Background="{TemplateBinding Background}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="16" />
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="16" />
                                        </Grid.ColumnDefinitions>
                                        <RepeatButton Grid.Column="0" Style="{DynamicResource ScrollBar_LineButton}" Command="ScrollBar.LineLeftCommand" Content="M 0 4 L 4 8 L 4 0 Z" />
                                        <!--<Border Grid.Column="1" BorderBrush="DarkBlue" BorderThickness="1" Background="{TemplateBinding Background}" CornerRadius="2" />
                                        <Track Grid.Column="1" Name="PART_Track" IsDirectionReversed="false">
                                            <Track.DecreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBar_PageButton}"/>
                                            </Track.DecreaseRepeatButton>
                                            <Track.Thumb>
                                                <Thumb Style="{StaticResource ScrollBar_Thumb}" MinWidth="4"/>
                                            </Track.Thumb>
                                            <Track.IncreaseRepeatButton>
                                                <RepeatButton Style="{StaticResource ScrollBar_PageButton}"/>
                                            </Track.IncreaseRepeatButton>
                                        </Track>-->
                                        <RepeatButton Grid.Column="2" Style="{DynamicResource ScrollBar_LineButton}" Command="ScrollBar.LineRightCommand" Content="M 0 0 L 0 8 L 4 4 Z" />
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>


            <!-- PanelExpander -->
            <ControlTemplate x:Key="PanelExpanderToggleButton" TargetType="ToggleButton">
                <Border
    Name="Border" 
    CornerRadius="0,0,0,0"
    Background="Transparent"
    BorderBrush="{StaticResource BorderBrush}"
    BorderThickness="0,0,0,0">
                    <!-- <Path
            Name="Arrow"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Data="M 0 0 L 4 4 L 8 0 Z"
            Fill="{StaticResource GlyphBrush}">
                    </Path>-->
                    <Path Name="Arrow" 
                          Stroke="{StaticResource ForegroundBrush}"
                          StrokeThickness="1px" StrokeLineJoin="Miter"
                          StrokeEndLineCap="Flat"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center"
                          Fill="{StaticResource BackgroundBrush}"
                          Data="M 1.0361386 3.431188 L 15.091584 3.4762375 L 8.108911 13.477228 L 1.0361386 3.431188 z"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="False">
                        <Setter TargetName="Arrow" Property="RenderTransform">
                            <Setter.Value>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                                    <SkewTransform AngleX="0" AngleY="0"/>
                                    <RotateTransform Angle="180"/>
                                    <TranslateTransform X="16" Y="16"/>
                                </TransformGroup>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource GlyphOverBrush}"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource GlyphPressedBrush}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style x:Key="PanelExpander" TargetType="Expander">

                <Setter Property="FontSize" Value="14px"/>
                <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
                <Setter Property="BorderBrush" Value="{StaticResource BorderBrush}" />
                <Setter Property="Background" Value="{StaticResource PanelBackgroundBrush}" />

                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Expander">
                            <Border
                     Name="Border"
                       BorderThickness="0,1,0,0"
                       BorderBrush="{StaticResource BorderBrush}"
                       Background="{StaticResource PanelBackgroundBrush}">
                                
                                <Grid>

                                    <Grid.RowDefinitions>

                                        <RowDefinition Name="ContentRow" Height="0"/>
                                        <RowDefinition Name="ToggleRow" Height="15"/>
                                    </Grid.RowDefinitions>

                                    <Grid Grid.Row="1">


                                        <ToggleButton
                           Grid.Column="0"
                           Background="{StaticResource NormalBrush}"
                           IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                           OverridesDefaultStyle="True"
                           Template="{StaticResource PanelExpanderToggleButton}" VerticalAlignment="Center"/>

                                    </Grid>
                                    <Grid Grid.Row="0">
                                        <Grid.RowDefinitions>

                                            <RowDefinition Name="HeaderRow" Height="30"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                
                                        <ContentPresenter
                                            Name="ExpanderHeader"
                          Grid.Row="0"
                           HorizontalAlignment="Left"
                           Margin="4"
                           ContentSource="Header"
                           RecognizesAccessKey="True"/>


                                        <Border
                     Name="Content"
                     Grid.Row="1" 
                     SnapsToDevicePixels="True"
                     Background="{StaticResource BackgroundBrush}"
                     BorderBrush="{StaticResource BorderBrush}"
                     BorderThickness="1,1,1,1"
                     CornerRadius="1,1,1,1" 
                     Margin="5,0,5,0">

                                            <ContentPresenter 
                                               x:Name="ExpandSite"
                         
                                                Margin="0,4,0,4">

                                                <ContentPresenter.LayoutTransform>
                                                    <ScaleTransform ScaleY="0"/>
                                                </ContentPresenter.LayoutTransform>
                                            </ContentPresenter>
                                        </Border>
                                    </Grid>
                                </Grid>

                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}"/>
                                    <!--<Setter TargetName="HeaderRow" Property="Height" Value="{Binding ElementName=Header,Path=DesiredHeight}"/>
                            <Setter TargetName="HeaderContent" Property="Visibility" Value="Visible"/>-->
                                    <Trigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName ="ExpandSite" 
                                                                 Storyboard.TargetProperty ="LayoutTransform.ScaleY" To ="1" Duration ="0:0:0.2"/>
                                                <DoubleAnimation Storyboard.TargetName ="ExpanderHeader" 
                                                                 Storyboard.TargetProperty="Opacity" To ="1" Duration ="0:0:0.4"/>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </Trigger.EnterActions>
                                    <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName ="ExpandSite"
                                                                 Storyboard.TargetProperty ="LayoutTransform.ScaleY" To=" 0" Duration ="0:0:0.2"/>
                                            <DoubleAnimation Storyboard.TargetName ="ExpanderHeader" 
                                                                 Storyboard.TargetProperty="Opacity" To="0" Duration ="0:0:0.4"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                    </Trigger.ExitActions>
                                </Trigger>
                                <!--<Trigger Property="IsEnabled" Value="False">
                     <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/>
                     <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}"/>
                     <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                  </Trigger>-->
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>



        </ResourceDictionary>

    </ListBox.Resources>

    <ListBox.Style>
        <Style x:Key="{x:Type ListBox}" TargetType="ListBox">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="SelectionMode" Value="Single"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Visible"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
            <Setter Property="BorderBrush" Value="{StaticResource BorderBrush}" />
            <Setter Property="ItemTemplate" Value="{StaticResource ScrollViewerItemTemplate}"/>

            <Setter Property="MinWidth" Value="120"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">


                        <Grid x:Name="PhotoScrollerGrid" AllowDrop="True">
                            <Grid.RowDefinitions>
                                <RowDefinition  Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Expander Style="{StaticResource PanelExpander}"  Height="Auto">

                                <Expander.Header>
                                    <Grid Width="Auto" >
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="150"/>
                                            <ColumnDefinition Width="150"/>
                                            <ColumnDefinition Width="25"/>
                                            <ColumnDefinition Width="25"/>
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Grid.Column="0" Grid.Row="0" Margin="10,0,0,0">Photo Sets</TextBlock>
                                        <ComboBox x:Name="PhotoSetComboBox" Width="150" Grid.Column="1" Grid.Row="0" ItemsSource="{Binding }" DisplayMemberPath="PhotoSetName"  SelectionChanged="PhotoSetComboBox_SelectionChanged" IsEditable="True" PreviewKeyDown="PhotoSetComboBox_PreviewKeyDown">

                                        </ComboBox>
                                        <Button x:Name="RemoveSetButton" Grid.Column="2" Grid.Row="0"  Content="-" Click="RemoveSetButton_Click"/>
                                    </Grid>
                                </Expander.Header>
                                <ScrollViewer Grid.Row="1" Grid.ColumnSpan="4" Margin="0"  MinHeight="75" >
                                    <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" />
                                </ScrollViewer>



                            </Expander>
                        </Grid>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>


        </Style>
    </ListBox.Style>

</ListBox>
